package com.k2.gulimall.member.service.impl;

import com.k2.gulimall.member.entity.MemberEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.k2.common.utils.PageUtils;
import com.k2.common.utils.Query;

import com.k2.gulimall.member.dao.MemberLevelDao;
import com.k2.gulimall.member.entity.MemberLevelEntity;
import com.k2.gulimall.member.service.MemberLevelService;


@Service("memberLevelService")
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelDao, MemberLevelEntity> implements MemberLevelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<MemberLevelEntity> queryWrapper = new QueryWrapper<MemberLevelEntity>();
        if (params.get("name")!=null&&params.get("name").toString().length()>0) {
            queryWrapper.like("name", params.get("name"));
        }
        IPage<MemberLevelEntity> page = this.page(
                new Query<MemberLevelEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

    @Override
    public List<MemberLevelEntity> getLevelNameToMemberLevel(String LevelName) {
        QueryWrapper<MemberLevelEntity> queryWrapper = new QueryWrapper<MemberLevelEntity>();
        queryWrapper.eq("name",LevelName);
        return this.list( queryWrapper );
    }

    @Override
    public MemberLevelEntity getMemberLevelToGrowth(Integer growthPoint) {
        QueryWrapper<MemberLevelEntity> queryWrapper = new QueryWrapper<MemberLevelEntity>();
        queryWrapper.orderByAsc("growth_point");
        queryWrapper.ge("growth_point",growthPoint);
        queryWrapper.last("limit 0,1");
        return this.getOne(queryWrapper);
    }

    @Override
    public MemberLevelEntity getMemberLevelToDefault() {
        QueryWrapper<MemberLevelEntity> queryWrapper = new QueryWrapper<MemberLevelEntity>();
        queryWrapper.eq("default_status",1);
        return this.getOne(queryWrapper);
    }

}